﻿#pragma once

#include <QObject>
#include "../dll_export.h"

class QTcpSocket;
class BASE_EXPORT TCPClient : public QObject
{
	Q_OBJECT

public:
	TCPClient(QObject* parent);
	~TCPClient();

	bool ConnectToHost(const QString& host, const unsigned int port);
	bool WaitForConnected(int ms);

	bool SendMessage(const QByteArray& data);
	bool SendMessageAndWaitAns(const QByteArray& data, QByteArray& ans, int timeoutMS = 3000);

	bool IsConnected();
	bool DisConnected();

signals:
	void ReceievedData(const QByteArray& data);
	void TcpDisconnected();

private slots:
	void OnDisconnected();
	void OnConnected();
	void OnReadyRead();

private:
	QString m_ip;
	QString m_port;
	QTcpSocket* m_socket;
};
